//前提
var mongoose = require("mongoose")

//引用插件
var mongoosePaginate = require('mongoose-paginate');

//约束
var schema = new mongoose.Schema({
  name: {
    type: String,
    required: [true, "产品名不能为空"]
  },
  product_type: {
    type: mongoose.Schema.Types.ObjectId,
  },
  describe: {
    type: String,
    required: [true, "产品描述不能为空"],
    maxlength: 200,
    minlength: [20, '产品描述不得少于20字']
  },
  buy_num: { //购买数量
    type: Number
  },
  price: { //价格
    type: String
  },
  hot: Boolean, //火热程度
  pro_data: {  //发表时间
    type: Date,
    default: Date.now
  },
  source: {  //地址
    type: String,
    required: [true, "地址不能为空"],
      },
  keywords: {
    type: Array //地址关键字
  },
  parameter:{
    type:Object //产品参数
  }
});



//引入插件
schema.plugin(mongoosePaginate);

//实例化
module.exports = mongoose.model('Product', schema, 'product'); // Model.paginate()